package com.szyjjk.config;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import com.szyjjk.constants.SzyjjkConstant;
public class LoginInterceptor implements HandlerInterceptor {
	
	


	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
        // 检查每个到来的请求对应的session域中是否有登录标识
		Object loginName = request.getSession().getAttribute(SzyjjkConstant.TOKEN);
	       // String urlLook = request.getRequestURL().toString();
		if (null == loginName || !(loginName instanceof String)) {
            // 未登录，重定向到登录页
        	request.setAttribute("msg","请先登录系统在访问");
        	request.getRequestDispatcher("/login.do").forward(request, response);
            return false;
        }
        return true;
		
	}
	@Override
	public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
	}

	@Override
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
			throws Exception {
	}

}
